﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
#region
/*
 * ========================================================================
 * Copyright(c) 2008-20112中山市金联网络有限公司, All Rights Reserved.
 * ========================================================================
 *  
 * 【当前类文件的功能】
 *  
 *  
 * 作者：fei peng   时间：9/6/2013 10:18:12 AM
 * 文件名：HardwareUtil
 * 版本：V1.0.0
 * 
 * 修改者：           时间：               
 * 修改说明：
 * ========================================================================
*/
#endregion

namespace Service.ZSJL.Com.Hardware
{
    public class HardwareUtil
    {
        // 1，获取CPU编号
        public string GetCPUID()
        {
            ManagementClass mc = new ManagementClass("win32_processor");

            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                return mo["processorid"].ToString();
            }
            return "";
        }
        //2，获取主板ID
        public string GetBoardID()
        {
            System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
            foreach (ManagementObject mo in searcher.Get())
            {
                return (mo["SerialNumber"].ToString().Trim());

            }
            return "";
            //或者：
            //System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_BaseBoard");
            //ManagementObjectCollection moc = mc.GetInstances();
            //foreach (ManagementObject mx in moc)
            // {
            //     MessageBox.Show( mx.Properties["SerialNumber"].Value.ToString());
            //}

        }


        //3，获取硬盘ID
        public string GetHardDiskID()
        {
            System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_DiskDrive");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                return (mo.Properties["Model"].Value.ToString());
            } return "";
        }
        //4，获取网卡地址

        public string GetNetworkID()
        {
            System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if ((bool)mo["IPEnabled"] == true)
                    return (mo["MacAddress"].ToString());
                mo.Dispose();
            }
            return "";
        }
        //5,获取内存信息


        public string GetMemoryID()
        {
            System.Management.ManagementClass mcMemory = new System.Management.ManagementClass("Win32_OperatingSystem");
            ManagementObjectCollection mocMemory = mcMemory.GetInstances();
            foreach (ManagementObject mo in mocMemory)
            {
                if (mo.Properties["TotalVisibleMemorySize"].Value != null)
                {
                    return (mo.Properties["TotalVisibleMemorySize"].Value.ToString());
                }
            }
            return "";
        }
    }

}
